package com.xh.hongaiagent.rag;

import org.springframework.ai.chat.client.advisor.RetrievalAugmentationAdvisor;
import org.springframework.ai.chat.client.advisor.api.Advisor;
import org.springframework.ai.rag.retrieval.search.DocumentRetriever;
import org.springframework.ai.rag.retrieval.search.VectorStoreDocumentRetriever;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.filter.Filter;
import org.springframework.ai.vectorstore.filter.FilterExpressionBuilder;



public class LoveAppRagCustomAdvisorFactory {
    /**
     * 自定义的RAG，支持按status过滤
     * @param vectorStore
     * @return
     */
    public static Advisor createLoveAppRagCustomAdvisor(VectorStore vectorStore) {

        // 创建过滤条件

//        Filter.Expression filterExpression = new FilterExpressionBuilder()
//                .eq("status", status)
//                .build();

        // 创建向量存储检索器
        DocumentRetriever documentRetriever = VectorStoreDocumentRetriever.builder()
                .vectorStore(vectorStore)
//                .filterExpression(filterExpression)
                .similarityThreshold(0.3)
                .topK(3)
                .build();


        return RetrievalAugmentationAdvisor.builder()
                .documentRetriever(documentRetriever)
                .queryAugmenter(LoveAppContextualQueryAugmenterFactory.createLoveAppContextualQueryAugmenter())
                .build();
    }
}
